package com.lxp.modules.gyy.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.PageUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lxp.common.core.page.TableDataInfo;
import com.lxp.modules.gyy.domain.HrScore;
import com.lxp.modules.gyy.domain.vo.ScoreParam;
import com.lxp.modules.gyy.mapper.HrScoreMapper;
import com.lxp.modules.gyy.service.HrScoreService;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【hr_score(积分)】的数据库操作Service实现
 * @createDate 2024-04-25 10:44:44
 */
@Service
public class HrScoreServiceImpl extends ServiceImpl<HrScoreMapper, HrScore> implements HrScoreService {

    @Override
    public TableDataInfo getScoreByEmpId(ScoreParam param, TableDataInfo info) {
        int pageNum = info.getPageNum() - 1;
        Integer pageSize = info.getPageSize();
        int start = PageUtil.getStart(pageNum, pageSize);
        int endPage = PageUtil.getEnd(pageNum, pageSize);
        Date date = new Date();
        if (param.getStartDate() == null) {
            Date jdkDate = DateUtil.beginOfMonth(date).toJdkDate();
            param.setStartDate(jdkDate);
        }
        if (param.getEndDate() == null) {
            Date jdkDate = DateUtil.endOfMonth(date).toJdkDate();
            param.setEndDate(jdkDate);
        }
        List<HrScore> scoreList = this.baseMapper.getScoreByEmpId(param);
        info.setTotal(scoreList.size());
        if (scoreList.size() > endPage) {
            scoreList = scoreList.subList(start, endPage);
        } else {
            scoreList = scoreList.subList(start, scoreList.size());
        }
        info.setRows(scoreList);
        return info;
    }
}




